package com.masiyi;

import com.masiyi.dao.UserDao;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

/**
 * @Author masiyi
 * @Date ${DATE}
 * @PackageName:com.masiyi
 * @ClassName: ${NAME}
 * @Description: TODO
 * @Version 1.0
 */
public class Main {
    public static void main(String[] args) throws IOException {
        InputStream inputStream = Resources.getResourceAsStream("mybatis-config.xml");
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);

        try (SqlSession session = sqlSessionFactory.openSession()) {
            UserDao mapper = session.getMapper(UserDao.class);
            mapper.findById(1).forEach(System.out::println);
            System.out.println("----------------------------");
            mapper.findAll().forEach(System.out::println);

        }
    }
}